import neash.swf.SWF;
import neash.swf.MovieClip;


class SWFTest
{
   static public function CreateFromInput(inInput:flash.utils.IDataInput) : Void
   {
      var swf = new SWF(inInput);

      neash.Lib.Init("SWF",swf.Width(),swf.Height(),false,true); 
      neash.Lib.ShowFPS();
      var col:Null<Int> = swf.GetBackground(); 
      if (col!=null)
         neash.Lib.SetBackgroundColour(col);
      neash.Lib.SetFrameRate(swf.GetFrameRate()); 

      var movie = swf.CreateInstance();

      flash.Lib.current.addChild(movie);

      neash.Lib.Run(); 
   }


   static public function main() : Void
   {
      var swf = neash.Lib.parameters.param0;
      // For debugging, might just want to hardwire name in...
      if (swf==null || swf=="")
         swf = "Circle1.swf";

      if (swf==null)
      {
      #if !flash
         trace("Please provide a SWF filename as argument.");
      #else
         trace("Please provide a SWF filename with 'FlashVars' param0.");
      #end
      }
      else
      {
      #if !flash
         var file = neko.io.File.read(swf,true);
         CreateFromInput(new flash.utils.IDataInput(file) );
      #else
        var stream = new flash.net.URLStream();
        var request = new flash.net.URLRequest(swf);
        stream.addEventListener(flash.events.Event.COMPLETE, function(event)
           { CreateFromInput(stream);  } );
        stream.load(request);
      #end
      }
   }
}

